const getMenuList =(menuList)=>{
    let cloneData = JSON.parse(JSON.stringify(menuList))
    const treeData =  cloneData.filter(father => {
        let branchArr = cloneData.filter(child => {
            child.path = child.url.split('/')[1]
            return father.id == child.pid
        }); 
        
        branchArr.length > 0 ? father.children = branchArr : '';
        
        return father.pid == 0
      });
      treeData.sort((a,b)=>{
        return a.sort > b.sort?1:-1 
      })
      treeData.map((item)=>{
        if(item.children?.length){
          item.children.sort((c,d)=>{
            return c.sort>d.sort?1:-1
          })
        }
        
      })
    return treeData
}

export default getMenuList